<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="/">
		<TX>
			<xsl:for-each select="insupost-response">
				<TX_HEADER>
					<SYS_HDR_LEN>
						<xsl:value-of select="substring-before(response-head/column5,'#')" />
					</SYS_HDR_LEN>
					<SYS_PKG_VRSN>01</SYS_PKG_VRSN>
					<SYS_TTL_LEN>
						<xsl:value-of select="substring-after(response-head/column5,'&amp;')" />
					</SYS_TTL_LEN>
					<SYS_SND_SEC_ID>510047</SYS_SND_SEC_ID>
					<SYS_REQ_SEC_ID>
						<xsl:value-of select="response-head/column6" />
					</SYS_REQ_SEC_ID>
					<SYS_TX_TYPE>020000</SYS_TX_TYPE>
					<SYS_EVT_TRACE_ID>
						<xsl:value-of select="response-head/column7" />
					</SYS_EVT_TRACE_ID>
					<SYS_SND_SERIAL_NO>
						<xsl:value-of select="response-head/column8" />
					</SYS_SND_SERIAL_NO>
					<SYS_PKG_TYPE>1</SYS_PKG_TYPE>
					<SYS_MSG_LEN>
						<xsl:value-of select="substring-before(substring-after(response-head/column5,'#'),'&amp;')" />
					</SYS_MSG_LEN>
					<SYS_IS_ENCRYPTED>3</SYS_IS_ENCRYPTED>
					<SYS_ENCRYPT_TYPE>3</SYS_ENCRYPT_TYPE>
					<SYS_COMPRESS_TYPE>0</SYS_COMPRESS_TYPE>
					<SYS_EMB_MSG_LEN>0</SYS_EMB_MSG_LEN>
					<SYS_RECV_TIME>
						<xsl:value-of select="response-head/trans-date" />
						<xsl:value-of select="response-head/trans-time" />
						000
					</SYS_RECV_TIME>
					<SYS_RESP_TIME />
					<SYS_PKG_STS_TYPE>01</SYS_PKG_STS_TYPE>
					<SYS_TX_STATUS>
						<xsl:choose>
							<xsl:when test="response-head/trans-result = '0'">
								00
							</xsl:when>
							<xsl:otherwise>
								01
							</xsl:otherwise>
						</xsl:choose>
					</SYS_TX_STATUS>
					<SYS_RESP_CODE>
						<xsl:choose>
							<xsl:when test="response-head/trans-result = '0'">
								000000000000
							</xsl:when>
							<xsl:otherwise>
								<xsl:choose>
									<xsl:when test="response-head/column1 != ''">
										<xsl:value-of select="response-head/column1" />
									</xsl:when>
									<xsl:otherwise>
										ZZZ069000001
									</xsl:otherwise>
								</xsl:choose>
							</xsl:otherwise>
						</xsl:choose>
					</SYS_RESP_CODE>
					<SYS_RESP_DESC_LEN>
						<xsl:choose>
							<xsl:when test="response-head/trans-result = '0'">
								4
							</xsl:when>
							<xsl:otherwise>
								<xsl:call-template name="CountRspLen">
									<xsl:with-param name="rspDescLen" select="0" />
									<xsl:with-param name="errIdx" select="1" />
									<xsl:with-param name="errors" select="response-head/validity-errors" />
									<xsl:with-param name="errsLength" select="count(response-head/validity-errors/validity-error)" />
								</xsl:call-template>
							</xsl:otherwise>
						</xsl:choose>
					</SYS_RESP_DESC_LEN>
					<SYS_RESP_DESC>
						<xsl:choose>
							<xsl:when test="response-head/trans-result = '0'">
								交易成功
							</xsl:when>
							<xsl:otherwise>
								<xsl:for-each select="response-head/validity-errors/validity-error">
									<xsl:value-of select="error-desc" />
								</xsl:for-each>
							</xsl:otherwise>
						</xsl:choose>
					</SYS_RESP_DESC>
				</TX_HEADER>
				<TX_BODY>
					<COMMON>
						<FILE_NUM>
							<xsl:value-of select="response-head/column9" />
						</FILE_NUM>
						<FILE_MODE>0</FILE_MODE>
						<FILE_NAME>
							<xsl:value-of select="response-head/column10" />
						</FILE_NAME>
						<FILE_PATH>
							<xsl:value-of select="response-head/column11" />
						</FILE_PATH>
					</COMMON>
					<ENTITY>
						<COM_ENTITY>
							<Inst_Eng_ShrtNm>CCB</Inst_Eng_ShrtNm>
							<Ins_Co_ID>010067</Ins_Co_ID>
							<SvPt_Jrnl_No>
								<xsl:value-of select="response-head/trans-id" />
							</SvPt_Jrnl_No>
							<SYS_TX_CODE>P53816141</SYS_TX_CODE>
							<TXN_ITT_CHNL_ID>
								<xsl:value-of select="response-head/column12" />
							</TXN_ITT_CHNL_ID>
							<TXN_ITT_CHNL_CGY_CODE>
								<xsl:value-of select="response-head/column13" />
							</TXN_ITT_CHNL_CGY_CODE>
							<CCBIns_ID>
								<xsl:value-of select="response-head/post" />
							</CCBIns_ID>
							<CCB_EmpID>
								<xsl:value-of select="response-head/agency-hand" />
							</CCB_EmpID>
							<Ins_Co_Acg_Dt>
								<xsl:value-of select="translate(string(response-head/trans-date),'-','')" />
							</Ins_Co_Acg_Dt>
							<Ins_Co_Jrnl_No>
								<xsl:value-of select="response-head/trans-id" /><!-- 同交易流水号 -->
							</Ins_Co_Jrnl_No>
							<!-- 保险公司客户服务电话 -->
							<Ins_Co_Cst_Svc_Tel>
								<xsl:value-of select="response-head/column14" />
							</Ins_Co_Cst_Svc_Tel>
						</COM_ENTITY>
						<APP_ENTITY>
							<MainIns_Cvr>
								<xsl:if test="response-underwriting/uw-policy/discount-prem != ''">
									<xsl:value-of select="format-number(response-underwriting/uw-policy/discount-prem,&quot;#.00&quot;)" />
								</xsl:if>
							</MainIns_Cvr>
							<InsPrem_Amt>
								<xsl:if test="response-underwriting/policy-info/products/product/amount != ''">
									<xsl:value-of select="format-number(response-underwriting/policy-info/products/product/amount,&quot;#.00&quot;)" />
								</xsl:if>
							</InsPrem_Amt>
						</APP_ENTITY>
					</ENTITY>
				</TX_BODY>
			</xsl:for-each>
		</TX>
	</xsl:template>
	<xsl:template name="CountRspLen">
		<xsl:param name="rspDescLen" />
		<xsl:param name="errIdx" />
		<xsl:param name="errors" />
		<xsl:param name="errsLength" />
		<xsl:choose>
			<xsl:when test="not($errIdx &gt; $errsLength)">
				<xsl:call-template name="CountRspLen">
					<xsl:with-param name="rspDescLen" select="$rspDescLen+string-length($errors/validity-error[$errIdx]/error-desc)" />
					<xsl:with-param name="errIdx" select="$errIdx+1" />
					<xsl:with-param name="errors" select="$errors" />
					<xsl:with-param name="errsLength" select="$errsLength" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$rspDescLen" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>
